<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Actions on Object View</title>
<link type="text/css" href="JSP/css/style.css" rel="stylesheet"></link>
</head>
<%@include file="../checkSession.jsp"%>
<%@page import="java.util.LinkedList"%>
<%@page import="model.Table"%>
<%@page import="model.ActionLog"%>
<%@page import="model.User"%>
<%!
	LinkedList<Table>list1;
	LinkedList<User>list;
	LinkedList<ActionLog>listRS;
	String owner;
	String obj;
	String grantee;
	String statType;%>
<%
	list = (LinkedList<User>) request.getAttribute("lstUser");
	list1=(LinkedList<Table>)request.getAttribute("lstTable");
	listRS=(LinkedList<ActionLog>)request.getAttribute("lstRS");
	owner=(String)request.getAttribute("owner");
	obj=(String)request.getAttribute("obj");
	grantee=(String)request.getAttribute("grantee");
	statType=(String)request.getAttribute("stat");
	if (list == null) {
		out.println("NULL");
	} else {
		
		for(int i = 0 ; i< list1.size();i++){
			Table t = list1.get(i);
			
			if(t.ownerName.equalsIgnoreCase(owner)) {
				t = list1.remove(i);
				list1.addFirst(t);
				System.out.println("current user issssssssssssssss" + t.ownerName);
				break;
			}
			
		}
		if (grantee!= null && list!=null) {
			 
			
			for (int i = 0; i < list.size(); i++) {
				User u = list.get(i);
				if (u.username.equalsIgnoreCase(grantee)) {
					list.remove(i);
					list.addFirst(u);
					break;
				}

			}	
		}
%>
<body>
	<div id="wrap">
		<%@include file="adminHeader.jsp"%>
		<font size="3" face="verdana" color="orange">Action On Object Views</font>
		<div class="center_content">
			<%@include file="auditingLeftContent.jsp"%>
			<div class="right_content">
				<form action=<%="./SubmitViewObjectAudit?owner="+owner+"&obj="+obj%> method="post">
				<table border=0>
					<tr>
						<td>Object</td>
						<td></td>
						<td><select name="Table" onchange="window.location.href=this.value">
					<% 	
						for(int i=0; i<list1.size();i++){
							Table t = list1.get(i);
						
					 %>
						
							<option value=<%="./ViewObjectAudit?owner="+t.ownerName+"&obj="+t.tableName%>><%=t.ownerName+"."+t.tableName%></option>
					<%} %>
					</select></td>
					</tr>
					<tr>
						<td>User</td>
						<td></td>
						<td><select name="User">
								<%
									User u;
									for (int i = 0; i < list.size(); i++) {
									u = list.get(i);
									
								%>
								
								<option value=<%=u.username%>><%=u.username%></option>
								<%
									}
								%>
						</select></td>
					</tr>
					<tr>
						<td>Statement</td>
						<td></td>
						<td><select name="statType">
								
								<%String s1="",s2="",s3="",s4="",s5="",s6="",s7="";
							if("SELECT".equalsIgnoreCase(statType))s1="selected";
							else if("insert".equalsIgnoreCase(statType))s2="selected";
							else if("update".equalsIgnoreCase(statType))s3="selected";
							else if("delete".equalsIgnoreCase(statType))s4="selected";
							else if("all".equalsIgnoreCase(statType))s5="selected";%>
									<option value="SELECT" <%=s1 %>>SELECT</option>
									<option value="INSERT" <%=s2 %>>INSERT</option>
									<option value="UPDATE" <%=s3 %>>UPDATE</option>
									<option value="DELETE" <%=s4 %>>DELETE</option>
									<option value="ALL" <%=s5 %>>ALL DML</option>
								
						</select></td>
					</tr>
					<tr>
						<td><input type=submit name=confirm value="Confirm" /></td>
						<td></td>
						<td></td>
					</tr>
				</table>
				</form>

				<table border=1>
					<tr>
						<th class="table-header-repeat line-left minwidth-1">Object</th>
						<th class="table-header-repeat line-left minwidth-1">Action</th>
						<th class="table-header-repeat line-left">Time</th>
						<th class="table-header-repeat line-left" style="width: 200px;">SQLStatement</th>
					</tr>			
				<%
				if(listRS!=null){
					
					for (int i = 0; i < listRS.size(); i++) {
							ActionLog a = listRS.get(i);
				%>	
					<tr>
						<td><%=a.ownerObj+"."+a.object%></td>
						<td><%=a.action%></td>
						<td><%=a.time%></td>
						<td><%=a.sqlStat%></td>
					</tr>	
					
				<%	
					}
				
				}%>
				</table>
				<%} %>
			</div>
		</div>
	</div>
</body>
</html>